﻿using AutoMapper;
using Ducu.BLL.Entity;
using Ducu.SRV.ServiceInteface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ducu.SRV.Query;
using Global.Core.ExtensionMethod;

namespace Ducu.SRV.ProdService
{
    public class RegisterService : BaseService, IRegisterService
    {
        public bool IsUserNameExist(string userName)
        {
            Register register = repoFactory.Query<Register>()
                .GetPassword(userName).SingleOrDefault();
            return register != null;
        }

        public void Do(ViewModel.RegisterModel model)
        {
            Register register = Mapper.Map<Register>(model);
            register.Password = register.Password.Md5Encypt();
            register.User = new User
            {
                RegisterInfo = register,
                Profile = new Ducu.BLL.Entity.Profile { DisplayName = model.UserName }
            };

            repoFactory.Save(register);
        }
    }
}
